#!/bin/bash


echo 'verify required software...' 

if command -v gem >/dev/null 2>&1; then 
  echo 'installed gem' 
else 
  echo 'Error: no exists gem, please install ruby' 
  exit 1
fi

if command -v git >/dev/null 2>&1; then 
  echo 'installed git' 
else 
  echo 'Error: no exists git, please intall git' 
  exit 1
fi

cd $TMPDIR
if [ -d "extcocoapods" ]; then
	rm -rf extcocoapods
fi
mkdir extcocoapods
cd extcocoapods
echo 'start download...' 
git clone https://gitee.com/ext-cocoapods/CocoaPods.git 
echo 'download finished!' 
cd CocoaPods

if command -v pod >/dev/null 2>&1; then 
  echo 'installed cocoapods, start uninstall...' 
  gem uninstall --all --executables --force cocoapods 
fi

echo 'start build...' 
gem build cocoapods.gemspec
if [ $? -ne 0 ]; then
    echo "build Error"
	exit 1
fi

echo 'start install...' 
gem install --force --local *.gem
if [ $? -ne 0 ]; then
    echo "install Error"
	exit 1
fi

cd ../../
rm -rf extcocoapods

echo 'install finished!' 